package com.briup.ch08.ex;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * @Author briup-adam
 * @Date 2023/10/16 上午10:44
 * @Description
 **/

public class TreeMapDemo {
    public static void main(String[] args) {
        Comparator cmp=new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if (o1%2==0&&o2%2==0)
                    return o1-o2;
                else if(o1%2==1&&o2%2==1){
                    return o2-o1;
                }else if(o1%2==0&&o2%2==1){
                        return -1;
                }else {
                    return 1;
                }

            }
        };
        //指定客户化排序   比较器排序  自定义排序
        TreeMap map=new TreeMap(cmp);
        map.put(1,"乔辉");
        map.put(2,"姚文慧");
        map.put(40,"安大黔");
        map.put(39,"王欣宇");
        map.put(20,"赵振宇");

        for (Object o : map.entrySet()) {
            System.out.println(o);
        }
    }
}
